#include <stdio.h>

/*
	使用顺序存储结构或链式存储结构实现一元多项式的加法运算
*/

int main()
{
	int poly1[][2] = {{3, 4}, {-5, 2}, {6, 1}, {-2, 0}};
	int poly2[][2] = {{5, 20}, {-7, 4}, {3, 1}};
	int result[7][2];
	int i, j, k;
	for (i = 0, j = 0, k = 0; i < 4 && j < 3;)
	{
		if (poly1[i][1] == poly2[j][1])
		{
			result[k][1] = poly1[i][1];
			result[k++][0] = poly1[i++][0] + poly2[j++][0];
		}
		else if (poly1[i][1] > poly2[j][1])
		{
			result[k][0] = poly1[i][0];
			result[k++][1] = poly1[i++][1];
		}
		else
		{
			result[k][0] = poly2[j][0];
			result[k++][1] = poly2[j++][1];
		}
	}
	while (i < 4)
	{
		result[k][0] = poly1[i][0];
		result[k++][1] = poly1[i++][1];
	}
	while (j < 3)
	{
		result[k][0] = poly2[j][0];
		result[k++][1] = poly2[j++][1];
	}
	for (i = 0; i < k; i++)
	{
		printf("%d %d\n", result[i][0], result[i][1]);
	}
	return 0;
}
